package com.zx.git_mybatisplus_smbms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zx.git_mybatisplus_smbms.pojo.SmbmsUser;
import com.zx.git_mybatisplus_smbms.service.SmbmsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/users/")
@SessionAttributes(value = {"logUser"})
public class UserController {

   @Autowired
    private SmbmsUserService smbmsUserService;


    @RequestMapping("login")
    public String login( String userCode, Model model,String userPassword, HttpSession session) {
        SmbmsUser user = smbmsUserService.login(userCode, userPassword);
        if (user != null) {//成功
        model.addAttribute("logUser", user);
            // forward: 转发跳转到控制器
//            return "forward:list";
            return "frame";
//            return "redirect:list";
        } else { //失败
            model.addAttribute("msg", "用户名或密码错误！");
            //重定向  到根目录 /login.html
//            return "redirect:/login.html";
            return "login";
        }
    }

//    @RequestMapping("listpages/{current}/{size}")
        @RequestMapping("list/{current}")
        public String  listpages(@PathVariable("current") Integer current , Model model){
            Page<SmbmsUser> page=new Page<SmbmsUser>(current,3);
            Page<SmbmsUser> page1= smbmsUserService.page(page);
            model.addAttribute("upage",page1);
            return  "userlist";
        }




}
